package com.wlcj.www.model.main;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.wlcj.util.SqlUtil;

public class Content extends Model<Content> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5573179551852403795L;
	
	public static final Content dao = new Content();
	public List<Content> getListByTypeId(Integer type_id,Integer start,Integer limit){
		String sql = "select jc.content_id,jce.link link,jce.title_img title_img,jce.description description,jce.title title,jce.short_title short_title FROM jc_content jc,jc_content_ext jce where jc.content_id = jce.content_id and jc.status = 2 and jc.type_id = ? order by jc.top_level desc,jc.sort_date desc  LIMIT ?,?";
		return find(sql,type_id,start,limit);
	}
	public List<Content> getTouTiaoListByTypeId(Integer type_id,Integer start,Integer limit){
		String sql = "select jc.sort_date,jc.content_id,jce.link link,jce.title_img title_img,jce.description description,jce.title title,jce.short_title short_title,jc.penster_id,jce.author author,jch.channel_name channel_name FROM jc_content jc,jc_content_ext jce,jc_channel_ext jch where jch.channel_id = jc.channel_id and jc.content_id = jce.content_id and jc.status = 2 and jc.type_id = ? order by jc.top_level desc,jc.sort_date desc  LIMIT ?,?";
		return find(sql,type_id,start,limit);
	}
	public List<Content> getListByChannelId(Integer channelId,Integer start,Integer limit){
//		String sql = "select jc.sort_date,jc.content_id,jce.link link,jce.title_img title_img,jce.description description,jce.title title,jce.short_title short_title,jc.penster_id,jce.author author,jch.channel_name channel_name,jcl.channel_path FROM jc_content jc,jc_content_ext jce,jc_channel_ext jch,jc_channel jcl where jcl.channel_id =jc.channel_id and jch.channel_id = jc.channel_id and jc.content_id = jce.content_id and jc.status = 2 and jc.channel_id = ? order by jc.top_level desc,jc.sort_date desc  LIMIT ?,?";
		return find(SqlUtil.sql("content.getListByChannelId"),channelId,channelId,start,limit);
	}
	public List<Content> getListByChannelIds(int[] channelId,Integer start,Integer limit){
//		String sql = "select jc.sort_date,jc.content_id,jce.link link,jce.title_img title_img,jce.description description,jce.title title,jce.short_title short_title,jc.penster_id,jce.author author,jch.channel_name channel_name,jcl.channel_path FROM jc_content jc,jc_content_ext jce,jc_channel_ext jch,jc_channel jcl where jcl.channel_id =jc.channel_id and jch.channel_id = jc.channel_id and jc.content_id = jce.content_id and jc.status = 2 and jc.channel_id in (98,104) order by jc.top_level desc,jc.sort_date desc  LIMIT ?,?";
		return find(SqlUtil.sql("content.getListByChannelIds"),channelId[0],channelId[1],channelId[0],channelId[1],start,limit);
	}
	public List<Content> getListByIds(int[] ids){
		String count = "";
		List<Object> list = new ArrayList<Object>();
		for(int i=0;i<ids.length;i++){
			list.add(ids[i]);
			count += "?";
			if(i!=ids.length-1){
				count += ",";
			}
		}
		String sql = "select content_id,title,link,title_img from jc_content_ext where content_id in ("+count+")";
		return find(sql,list.toArray());
	}
	public List<Content> getListByChannelPath(String channelPath,Integer start,Integer end){
		return find(SqlUtil.sql("content.newslist"),channelPath,channelPath,start,end);
	}
	public Content getContentById(Integer contentId){
		return findFirst("select jce.description,jc.sort_date,jce.origin,jct.txt,jc.content_id,jc.channel_id,jc.penster_id,jce.author,jce.short_title,jce.title,jce.title_img,jce.content_img,jce.type_img,(select count(jct.comment_id) from jc_comment jct where jct.content_id =  jc.content_id) replys from jc_content jc left join jc_content_ext jce on jc.content_id = jce.content_id left join jc_content_txt jct on jc.content_id = jct.content_id where jc.content_id = ?",contentId);
	}
	public List<Content> getzhuanglanListByViewsAndId(Integer channelId,Integer start,Integer limit){
		return find(SqlUtil.sql("content.getzhuanglanListByViewsAndId"),channelId,channelId,start,limit);
	}
	public List<Content> getViewList(Integer start,Integer limit){
		return find(SqlUtil.sql("content.getViewList"),start,limit);
	}
	public List<Content> getListByPensterId(Integer pensterId,Integer start,Integer limit){
		String sql = "select  jc.content_id,jce.link link,jce.title title,jce.short_title short_title,jc.penster_id FROM jc_content jc,jc_content_ext jce where jc.content_id = jce.content_id and jc.status = 2 and jc.penster_id = ? order by jc.top_level desc,jc.sort_date desc  LIMIT ?,?";
		return find(sql,pensterId,start,limit);
	}
	public List<Content> getxiangguanwenzhangList(Integer contentId,Integer start,Integer limit){
		return find(SqlUtil.sql("content.xiangguanwenzhangtuijian"),contentId,start,limit);
	}
	public List<Content> getTuwenTuijian(String channelPath,Integer start,Integer end){
		return find(SqlUtil.sql("content.tuwentuijian"),channelPath,channelPath,start,end);
	}
	
	public List<Content> getTotal(Integer channelId){
		return find(SqlUtil.sql("content.getTotal"),channelId,channelId);
	}
}
